package com.kdzy.lshy.socity_server.controller;

import com.alibaba.fastjson.JSON;
import com.kdzy.lshy.socity_server.common.ExceptionDetailMessage;
import com.kdzy.lshy.socity_server.common.ResultMap;
import com.kdzy.lshy.socity_server.service.SendMessageService;
import io.swagger.annotations.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedHashMap;

/**
 * 推送消息接口
 * @author cly
 * @since 2018-06-21
 */
@RestController
@RequestMapping("/sendMessage")
@CrossOrigin("*")
@Api(value = "SendMessageController", description = "推送消息接口")
public class SendMessageController {

    private static final Logger logger = LoggerFactory.getLogger(SendMessageController.class);

    @Autowired
    private SendMessageService sendMessageService;

    /**
     * 推送消息 - 短信
     * @param param
     * @return json
     */
    @RequestMapping(value = "/send", method = RequestMethod.POST)
    @ApiOperation(notes = "/send", httpMethod = "POST", value = "推送消息 - 短信", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiResponses({
            @ApiResponse(code = 88, message = "参数为空"),
            @ApiResponse(code = 77, message = "数据库操作失败"),
            @ApiResponse(code = 98, message = "参数类型错误"),
            @ApiResponse(code = 99, message = "后台处理异常"),
            @ApiResponse(code = 1, message = "短信发送成功"),
            @ApiResponse(code = 11, message = "短信发送失败"),
            @ApiResponse(code = 0, message = "保存数据成功")
    })
    public Object list(
            @ApiParam(
                    required = true,
                    name = "param",
                    value = "{\n" +
                            " \"ID\": \"主键\",\n" +
                            " \"stamp\": 时间戳,\n" +
                            " \"is_used\": 是否有效 0:有效 1:无效,\n" +
                            " \"version\": 版本 0:测试 1:生产,\n" +
                            " \"visit_plat\": 访问平台 0:网页 1:一体机 2:小程序 3:其他,\n" +
                            " \"visit_type\": 访问类型 0:测试 1:生产,\n" +
                            " \"bizz_type\": 1 预约2 本社区待审核 3 本社区通过（4失败）5第三方已提交 6第三方待审核 7第三方成功（8第三方失败） 9 其他\n" +
                            "}")
            @RequestParam(name = "param") String param){
        logger.info("进入《推送消息 - 短信》list()方法；入参param = " + param);
        return sendMessageService.sendMessage(param);
    }

    /**
     * 推送消息 - 短信 - 居住证办理
     * @param param
     * @return json
     */
    @RequestMapping(value = "/sendResidencePermit", method = RequestMethod.POST)
    @ApiOperation(notes = "/sendResidencePermit", httpMethod = "POST", value = "推送消息 - 短信 - 居住证办理", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiResponses({
            @ApiResponse(code = 88, message = "参数为空"),
            @ApiResponse(code = 77, message = "数据库操作失败"),
            @ApiResponse(code = 98, message = "参数类型错误"),
            @ApiResponse(code = 99, message = "后台处理异常"),
            @ApiResponse(code = 1, message = "短信发送成功"),
            @ApiResponse(code = 11, message = "短信发送失败"),
            @ApiResponse(code = 0, message = "保存数据成功")
    })
    public Object sendResidencePermit(
            @ApiParam(
                    required = true,
                    name = "param",
                    value = "{\n" +
                            " \"ID\": \"主键\",\n" +
                            " \"stamp\": 时间戳,\n" +
                            " \"is_used\": 是否有效 0:有效 1:无效,\n" +
                            " \"version\": 版本 0:测试 1:生产,\n" +
                            " \"visit_plat\": 访问平台 0:网页 1:一体机 2:小程序 3:其他,\n" +
                            " \"visit_type\": 访问类型 0:测试 1:生产,\n" +
                            " \"res_type\": 1:提交材料 2:资料有误 3:资料正确  4发送上门短信通知  5:上门审核后失败（不在家） 6:上门审核后成功 7:已发放 8:上门审核后失败（在家）\n" +
                            " \"toHomeDate\": \"上门审核日期(当res_type = 4时)\"" +
                            "}")
            String param){
        logger.info("进入《推送消息 - 短信 - 居住证办理》sendResidencePermit()方法；入参param = " + param);
        return sendMessageService.sendResidencePermit(param);
    }

}
